﻿using System;
using System.Windows.Forms;
using dk.Helper.Base;

namespace dk.Helper.Controls
{
    public partial class AddAllyForm : Form
    {
        private readonly IWorld world;

        public AddAllyForm(IWorld world)
        {
            this.world = world;
            InitializeComponent();
        }

        public IAlly Ally { get; private set; }

        private void txtAllyTag_TextChanged(object sender, EventArgs e)
        {
            lstAllies.Items.Clear();
            string txtAllyTagTextToLower = txtAllyTag.Text.ToLower();
            foreach (string allyTag in world.Allies.AlliesByTag.Keys)
            {
                if (allyTag.ToLower().Contains(txtAllyTagTextToLower))
                {
                    lstAllies.Items.Add(allyTag);
                }
            }
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            Ally = lstAllies.SelectedItem == null ? null : world.Allies.AlliesByTag[lstAllies.SelectedItem.ToString()];
        }

        private void AddAllyForm_Load(object sender, EventArgs e)
        {
            txtAllyTag.Select();
        }
    }
}